package com.lgmshare.component.app;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import com.lgmshare.component.logger.Logger;

/**
 * dialog基类
 * <p>dialog尽量不复用，dismiss后直接销毁回收。
 *
 * @author lim
 * @description: TODO
 * @email lgmshare@gmail.com
 * @datetime 2016/5/19 17:56
 */
public abstract class LaraDialog extends Dialog {

    protected final String TAG = LaraDialog.this.getClass().getName();

    private View mRootView;

    public LaraDialog(Context context) {
        super(context);
    }

    public LaraDialog(Context context, int theme) {
        super(context, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Logger.v(TAG, "onCreate");
        int resId = onBindLayoutResId();
        if (resId > 0) {
            mRootView = View.inflate(getContext(), resId, null);
            setContentView(mRootView);
            initView();
        }
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Logger.v(TAG, "onAttachedToWindow");
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        Logger.v(TAG, "onDetachedFromWindow");
    }

    /**
     * 绑定布局资源文件ID
     * use with {@link #onCreate(Bundle)}
     *
     * @return 资源布局文件ID
     */
    protected abstract int onBindLayoutResId();

    /**
     * 初始化View
     * use with {@link #onBindLayoutResId()}
     */
    protected abstract void initView();
}
